package com.yl.chainStore.entity.warehouse

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.chainStore.common.enums.Status
import com.yl.chainStore.common.enums.TypeEnum
import com.yl.chainStore.util.GenerateNum
import com.yl.common.annotation.NoArg
import com.yl.common.getContext
import java.util.*

/**
 * <p>
 * 损益单
 * </p>
 *
 * @author cxw
 * @since 2021-07-22
 */
@NoArg
@TableName("warehouse_profit_loss_order")
data class WarehouseProfitLossOrder(

	/**
	 * 仓库物品损益表
	 */
	@TableId(value = "id", type = IdType.AUTO)
	var id: Long,

	/**
	 * 创建时间
	 */
	@TableField("create_time")
	var createTime: Date = Date(),

	/**
	 * 执行时间
	 */
	@TableField("deal_time")
	var dealTime: Date? = null,

	/**
	 * 创建人
	 */
	@TableField("create_user_id")
	var createUserId: Long = getContext().userId,

	/**
	 * 操作人
	 */
	@TableField("order_user_id")
	var orderUserId: Long = createUserId,

	@TableField(exist = false)
	var orderUserName:String ?= null,
	/**
	 * 审核人
	 */
	@TableField("deal_user_id")
	var dealUserId: Long? = null,

	/**
	 * 仓库id
	 */
	@TableField("dept_id")
	var deptId: Long = getContext().subCompanyId,

	@TableField(exist = false)
	var deptName: String? = null,

	/**
	 * 公司id
	 */
	@TableField("company_id")
	var companyId: Long = getContext().companyId,

	/**
	 * 损益类型
	 */
	@TableField("order_type")
	var orderType: TypeEnum = TypeEnum.WAREHOUSE_PROFIT_LOSS_TYPE_NEW_ADD,

	/**
	 * 状态
	 */
	@TableField("status")
	var status: Status = Status.UNKNOWN,

	/**
	 * 备注
	 */
	@TableField("remark")
	var remark: String? = null,

	/**
	 * 数据有效性
	 */
	@TableField("enabled")
	var enabled: Int = 1,

	/**
	 * 订单时间
	 */
	@TableField("order_time")
	var orderTime: Date = Date(),

	/**
	 * 单号
	 */
	@TableField("order_num")
	var orderNum: String = generateOrder("PL"),

	@TableField(exist = false)
	var details:List<WarehouseProfitLossOrderDetail>?=null
	) {

	val orderIsSelf: Boolean
		get() {
			return createUserId == getContext().userId
		}

	companion object : GenerateNum()
}
